﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace lchealthy
{
    public partial class frmDietitianShow : Form
    {
        
        public frmDietitianShow()
        {
            InitializeComponent();
        }
        DataSet ds;
       private void frmDietitianShow_Load(object sender, EventArgs e)
        {
            dieBind();
        }
       private void dieBind()
       { 
          string sql = "select * from dietitianinfo ";
            ds = DbHelperOleDb.Query(sql);
            dgvDietitian.AutoGenerateColumns = false;
            dgvDietitian.DataSource = ds.Tables[0];
       }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string name = txtName.Text;
            string sql = "select * from dietitianinfo where dName like'" + name+"%'";
             ds = DbHelperOleDb.Query(sql);
            dgvDietitian.DataSource = ds.Tables[0];
           
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            int row = dgvDietitian.CurrentRow.Index;
            int id = int.Parse(ds.Tables[0].Rows[row]["dID"].ToString());//选中的营养师的id
            frmNewDietitian f = new frmNewDietitian(id);
            f.ShowDialog();
            dieBind();

        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            int row = dgvDietitian.CurrentRow.Index;
            int id = int.Parse(ds.Tables[0].Rows[row]["dID"].ToString());//选中的营养师的id
            string sql = "select  * from dietitianinfo where dID=" + id;
            ds = DbHelperOleDb.Query(sql); ;
            string name=ds.Tables[0].Rows[0]["dName"].ToString();

           DialogResult  y= MessageBox.Show("确实要删除营养师"+name+"的信息吗？","提示",MessageBoxButtons.OKCancel);
           if (y == DialogResult.OK)
           {
                sql= "delete from  dietitianinfo  where  dID= " + id;
               int i = DbHelperOleDb.ExecuteSql(sql);
               if (i == 1)
               {
                   MessageBox.Show("删除营养师" + name + "的信息成功！");
                   dieBind();
               }
               else
               {
                   MessageBox.Show("删除营养师" + name + "的信息失败！");
               }
           }

        }

        private void txtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                btnSearch_Click(null, null);
            }
        }


       

        
    }
}
